//
//  LeftImageCell.m
//  Product_NEWS
//
//  Created by dllo on 16/1/4.
//  Copyright © 2016年 FCH. All rights reserved.
//



//图片
#define ImageView_X    10 * SCREEN_WIDTH

#define ImageView_Y     5 * SCREEN_HEIGHT

#define ImageView_W      SCREEN_WIDTH * 355 / 3

#define ImageView_H         SCREEN_WIDTH * 355 / 3  * 0.6
//标题
#define TitleLabel_X  (ImageView_X +  ImageView_W+ 10 * SCREEN_WIDTH)
#define TitleLabel_Y   ImageView_Y + 10 * SCREEN_HEIGHT
#define TitleLabel_W            (355 *SCREEN_WIDTH  - TitleLabel_X - 10 * SCREEN_WIDTH)
#define TitleLabel_H           ImageView_H * 0.6

//横线
#define LINE_X ImageView_X
#define LINE_Y (ImageView_Y + ImageView_H + 10 * SCREEN_HEIGHT)
#define LINE_W 335 * SCREEN_WIDTH
#define LINE_H 1 * SCREEN_HEIGHT

//来源
#define SourceLabel_X ImageView_X
#define SourceLabel_Y LINE_Y + 10 *SCREEN_HEIGHT
#define SourceLabel_W 150 *SCREEN_WIDTH
#define SourceLabel_H 20 *SCREEN_HEIGHT

#import "LeftImageCell.h"
#import "UIImageView+WebCache.h"

@interface LeftImageCell ()
@property (nonatomic, retain) UIImageView *leftImageView; //左单一的一个图
@property (nonatomic, retain) UILabel *titleLabel;  //标题

@property(nonatomic,retain)UIView *lineView;
@property (nonatomic, retain) UILabel *sourceLabel;  //左下角来源

@end


@implementation LeftImageCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createSubViews];
    }
    
    return  self;
    
}

-(void)createSubViews
{
    self.leftImageView = [[UIImageView alloc]initWithFrame:CGRectMake(ImageView_X, ImageView_Y, ImageView_W, ImageView_H)];
    [self.contentView addSubview:self.leftImageView];

    self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(TitleLabel_X, TitleLabel_Y, TitleLabel_W, TitleLabel_H)];
    
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    self.titleLabel.numberOfLines = 2;
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    self.lineView = [[UIView alloc]initWithFrame:CGRectMake(LINE_X, LINE_Y, LINE_W, LINE_H)];
    
    self.lineView.backgroundColor = [UIColor colorWithWhite:0.931 alpha:1.000];
    
    [self.contentView addSubview:self.lineView];
    [_lineView release];
    self.sourceLabel =  [[UILabel alloc]initWithFrame:CGRectMake(SourceLabel_X, SourceLabel_Y, SourceLabel_W, SourceLabel_H)];
    
    self.sourceLabel.font = [UIFont systemFontOfSize:13];
    self.sourceLabel.textColor = [UIColor colorWithWhite:0.584 alpha:1.000];
    
    [self.contentView addSubview:self.sourceLabel];
    [_sourceLabel release];
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, SourceLabel_Y + SourceLabel_H + 10 , 375 * SCREEN_WIDTH, 34)];
    view.backgroundColor = [UIColor colorWithWhite:0.945 alpha:1.000];
    [self.contentView addSubview:view];
}


-(void)setModel:(ReadListModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.leftImageView sd_setImageWithURL:[NSURL URLWithString:model.imgsrc] placeholderImage:[UIImage imageNamed:@"contentview_imagebg_logo@2x"]];
    
    self.titleLabel.text = model.title;
    self.sourceLabel.text = model.source;
    
}

+ (CGFloat)heightForRowWithReadNews:(ReadListModel *)readNews {
    return ImageView_H + 89;
}



- (void)dealloc {
    [_sourceLabel release];
    [_lineView release];
    [_titleLabel release];
    [super dealloc];
}




@end
